import { Modal } from 'antd';

/** 操作确认
 * @param operate 操作名称
 * @param handle 操作方法
 * @param data 操作数据
 */
export const axConfirm = (operate: any, handle: any, data: any) => {
  if (data.length > 0) {
    Modal.confirm({
      title: '操作确认',
      content: `确认对这${data.length}条数据进行${operate}操作？`,
      okText: '确认',
      cancelText: '取消',
      onOk: () => handle(operate, data),
    });
  }
};

/** 对数组进行分组
 * @param list 数组
 * @param field 分组字段
 */
export const axGroupArr: any = (list: any, field: any) => {
  let group: any = [];
  list.forEach((i: any) => {
    const f = group.find((j: any) => i[field] === j[field]);
    if (f) f.count++;
    else {
      group.push({
        [field]: i[field],
        count: 1
      });
    }
  });
  return group;
};
